/*
 * baseexception.h
 *
 *  Created on: Oct 20, 2011
 *      Author: fferri
 */

#pragma once
#ifndef BASEEXCEPTION_H_
#define BASEEXCEPTION_H_

#include <exception>
#include <iostream>
#include <string>
#include <sstream>
#include <boost/filesystem.hpp>


namespace lpe {
	namespace core {

		template<typename T>
		void launchException(std::string file, unsigned int line, std::string message)
		{
			T t;
			t.composeMessage(file,line, message);
			throw t;

		}

		class LPE_Base_Exception: public std::exception {
		protected:
			std::string m_err_msg;
		public:
			void composeMessage(const std::string& file, unsigned int line, const std::string& message)
			{
				std::stringstream ss;
				ss << boost::filesystem::path(file).filename() << ":" << line <<"\n\t"<< message;
				m_err_msg = ss.str();
			}
			LPE_Base_Exception(void) throw()
				:m_err_msg("LPE internal error")
			{}

			explicit LPE_Base_Exception(const std::string& msg) throw()
					:m_err_msg(msg)
			{}
			explicit LPE_Base_Exception(const char* msg) throw()
					:m_err_msg(msg)
			{}
			virtual const char* what() const throw()
			{
				return m_err_msg.c_str();
			}
			virtual ~LPE_Base_Exception() throw(){}
		};
	}
}
#endif /* BASEEXCEPTION_H_ */
